﻿
namespace 贪吃蛇
{
    class Start : Game
    {
        public override void start() 
        {
            //Console.WriteLine("开始场景");
            int minIndex = 0; int maxIndex = 2;
            int menuIndex = minIndex;
            writeMenu(menuIndex);
            while (Game.scene == E_Scene.Start)
            {
                switch (Console.ReadKey(true).Key)
                {
                    case ConsoleKey.W:
                    case ConsoleKey.UpArrow:
                        menuIndex--;
                        if (menuIndex < minIndex)
                        {
                            menuIndex = maxIndex;
                        }
                        writeMenu(menuIndex);
                        break;
                    case ConsoleKey.S:
                    case ConsoleKey.DownArrow:
                        menuIndex++;
                        if (menuIndex > maxIndex)
                        {
                            menuIndex = minIndex;
                        }
                        writeMenu(menuIndex);
                        break;
                    case ConsoleKey.Enter:
                    case ConsoleKey.Spacebar:
                        if ((E_Choice)menuIndex == E_Choice.Play)
                            Game.scene = E_Scene.Play;
                        else if ((E_Choice)menuIndex == E_Choice.Diffuculty)
                            Game.scene = E_Scene.Diffuculty;
                        else
                            Environment.Exit(0);
                        break;
                    default:
                        break;
                }
            }
        }
        public void writeMenu(int index)
        {
            Console.Clear();
            //标题
            E_Choice choice = (E_Choice)index; 
            Console.SetCursorPosition(Game.bufWidth / 2 - 3, Game.bufHeight / 6);
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("贪吃蛇");
            //选项1
            if (choice == E_Choice.Play)
                Console.ForegroundColor = ConsoleColor.Red;
            else
                Console.ForegroundColor = ConsoleColor.White;
            Console.SetCursorPosition(Game.bufWidth / 2 - 4, Game.bufHeight / 3);
            Console.WriteLine("开始游戏");
            //选项2
            if (choice == E_Choice.Diffuculty)
                Console.ForegroundColor = ConsoleColor.Red;
            else
                Console.ForegroundColor = ConsoleColor.White;
            Console.SetCursorPosition(Game.bufWidth / 2 - 4, Game.bufHeight / 2);
            Console.WriteLine("难度选择");
            if (choice == E_Choice.End)
                Console.ForegroundColor = ConsoleColor.Red;
            else
                Console.ForegroundColor = ConsoleColor.White;
            Console.SetCursorPosition(Game.bufWidth / 2 - 4, Game.bufHeight * 2 / 3);
            Console.WriteLine("结束游戏");
            Console.ForegroundColor = ConsoleColor.White;
        }
    }
    enum E_Choice
    {
        Play, Diffuculty, End
    }
}